package com.example.onlineeducation.viewmodel

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import androidx.paging.PagingData
import androidx.paging.cachedIn
import com.example.onlineeducation.base.BaseViewModel
import com.example.onlineeducation.data.model.CertificateListDataModel
import com.example.onlineeducation.repository.StudyRepository
import kotlinx.coroutines.flow.collectLatest

class CertificateVM : BaseViewModel() {
    private val mStudyRepository: StudyRepository by lazy { StudyRepository(mApiService) }

    
    private val _mCertificateListDataModel = MutableLiveData<PagingData<CertificateListDataModel>>()
    val mCertificateListDataModel: LiveData<PagingData<CertificateListDataModel>> = _mCertificateListDataModel
    
    
    fun getCertificateListPager(proId: String) = ycLaunch {
        mStudyRepository.getCertificateListPager(proId).cachedIn(viewModelScope).collectLatest {
            _mCertificateListDataModel.postValue(it)
        }
    }

}
